package day9.Exer;

import java.util.Scanner;

public class LeasingCenter {
    private String name;
    private String phone;
    Customer[] message = new Customer[20];
    Car[] arr = new Car[20];
    int count1 = 0;//记录车数量
    int count2 = 0;//记录租车客户数量

    public LeasingCenter(String name, String phone) {
        this.name = name;
        this.phone = phone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void showcenter() {
        System.out.println(getName() + "欢迎您，请致电" + getPhone() + "洽谈业务");
        this.showsum();
    }
    //购车
    public void addcar(Car a) {
        if (count1 >= arr.length) {
            Car[] arr2 = new Car[arr.length + 10];
            for (int i = 0; i < arr.length; i++) {
                arr2[i] = arr[i];
            }
            arr = arr2;
        }
        arr[count1] = a;
        count1++;
    }
    //查看可以租的车状态为true的信息
    public void showCarin(String chosenCar) {
        if (chosenCar.equals("轿车")) {
            System.out.println("现有车辆如下：");
            for (int i = 0; i < count1; i++) {
                if ((arr[i] instanceof Saloon) && (arr[i].isRent() == true)) {
                    arr[i].showinfo();
                }
            }
        } else if (chosenCar.equals("客车")) {
            System.out.println("现有车辆如下：");
            for (int i = 0; i < count1; i++) {
                if ((arr[i] instanceof Passenger) && (arr[i].isRent() == true)) {
                    arr[i].showinfo();
                }
            }
        }


    }
    //租车，如果车被租出去改为false“已出租”
    public void leasecar(String carNo) {
        for (int i = 0; i < count1; i++) {
            if (i == count1) {
                System.out.println("抱歉我们没有这辆车");
            } else if ((arr[i].getCarNo().equals(carNo))) {
                arr[i].setRent(false);
                arr[i].showforleasing();
            }
        }
    }
//添加租赁信息
    public void addmessage(Customer a) {
        if (count2 >= message.length) {
            Customer[] message2 = new Customer[message.length + 10];
            for (int i = 0; i < message2.length; i++) {
                message2[i] = message[i];
            }
            message = message2;
        }
        message[count2] = a;
        count2++;
    }
//展示租赁信息
    public void showMessage() {
        for (int i = 0; i < count2; i++) {
            System.out.println("客户" + message[i].getCustName() + "电话" + message[i].getCustPhone() + "租车日期" + message[i].getCustDate() + "所租车车牌" + message[i].getCarNo() + "租借天数" + message[i].getDay() + "天。");
        }
    }
//还车
    public void giveback(String carNo) {
        //int i = 0;//通过车牌找到这辆车
        for (int i = 0; i < count1; i++) {
            if (arr[i].getCarNo().equals(carNo)) {
                {
                    if (arr[i].isRent() == false) {
                        arr[i].setRent(true);
                        System.out.println("还车成功，下次继续合作！");
                        }
                        break;
                    } else {
                        System.out.println("这辆车为出租出去，信息错误");
                    }
                }
                System.out.println("归还失败，请核对信息！");
            }

        }
    }
//报废
    public void scrap(String carNo) {
        int i = 0;
        for (i = 0; i < count1; i++) {
            if (arr[i].getCarNo().equals(carNo)) {
                if (arr[i].isRent() == true) {
                    for (int j = i; j < count1 - 1; j++) {
                        arr[j] = arr[j + 1];
                    }
                    arr[count1 - 1] = null;
                    count1--;
                    System.out.println("报废成功！");
                    break;
                }
                System.out.println("这辆车租出去了，请等顾客退回后再报废");
            }
        }
        if (i == count1) {
            System.out.println("这辆车不是我们的，请重新选择！");
        }


    }

    public void showAllcar() {
        for (int i = 0; i < count1; i++) {
            arr[i].showinfo();
        }
    }

    public void showsum() {
        System.out.println("本公司现有" + count1 + "辆车可以租！");
    }
//计算租金
    public void calRent(String carNo, int day) {
        for (int i = 0; i < count1; i++) {
            if (arr[i].getCarNo().equals(carNo)) {
                System.out.println("请支付" + arr[i].calRent(day) + "元。");
                System.out.println("用车愉快");
            }
        }
    }

}
